/**
 * 主要用于获取点击左边栏来获取数据
 */

$(document).ready(
    function () {

        // 获取主机地址之后的目录
        var curWwwPath = window.document.location.href;

        /**
         * 获取项目根路径
         *
         * @returns {string} 返回路径地址
         */
        function getRootPath() {
            return "http://127.0.0.1";
        }


        /**
         * 电视+
         */
        if (curWwwPath.indexOf("one=TvPlus&two=Context") > 0) {

            /***
             * 进行AJAX请求
             */
            $.ajax({
                type: "POST",
                async: false,
                url: getRootPath() + "/manager/obtainArticle.do",
                data: "oneClass=TvPlus",
                success: function (data) {
                    //会话超时判断
                    if (data.length == 73) {
                        alert("会话已超时");
                        document.location = 'signin.html';
                    }

                    /**
                     * 遍历文章
                     */
                    $.each(data.data, function (key, article) {
                        /**
                         * 遍历资源信息
                         */
                        $.each(article.resource, function (key, resources) {
                            $("#communalList").append(
                                '<tr><td>' + resources.id + '</td>' +
                                '<td>' + article.twoClass + '</td>' +
                                '<td>' + article.titleName + '</td>' +
                                '<td>' + resources.type + '</td>' +
                                '<td>' + resources.pathName + '</td>' +
                                '<td>' + resources.state + '</td>' +
                                '<td>' + resources.sorting + '</td>' +
                                '<td>' + resources.clickPath + '</td>' +
                                '<td><div class="btn-group"><a data-toggle="dropdown" class="dropdown-toggle"><i class="fa fa-cog"></i></a> <ul role="menu" class="dropdown-menu pull-right"><li><a href=updateContent.html?id=' + resources.id + '>修改</a></li><li><a href=removeArticle.do?id=' + resources.artId + '>删除</a></li></ul></div></td></tr>'
                            );
                        });
                    });
                }
            });

        }/**
         *智慧生活
         */ else if (curWwwPath.indexOf("one=SmarterLife&two=Context") > 0) {
            /***
             * 进行AJAX请求
             */
            $.ajax({
                type: "POST",
                async: false,
                url: getRootPath() + "/manager/obtainArticle.do",
                data: "oneClass=SmarterLife",
                success: function (data) {
                    //会话超时判断
                    if (data.length == 73) {
                        alert("会话已超时");
                        document.location = 'signin.html';
                    }
                    $.each(data.data, function (key, article) {
                        /**
                         * 遍历资源信息
                         */
                        $.each(article.resource, function (key, resources) {
                            $("#communalList").append(
                                '<tr><td>' + resources.id + '</td>' +
                                '<td>' + article.twoClass + '</td>' +
                                '<td>' + article.titleName + '</td>' +
                                '<td>' + resources.type + '</td>' +
                                '<td>' + resources.pathName + '</td>' +
                                '<td>' + resources.state + '</td>' +
                                '<td>' + resources.sorting + '</td>' +
                                '<td>' + resources.clickPath + '</td>' +
                                '<td><div class="btn-group"><a data-toggle="dropdown" class="dropdown-toggle"><i class="fa fa-cog"></i></a> <ul role="menu" class="dropdown-menu pull-right"><li><a href=updateContent.html?id=' + resources.id + '>修改</a></li><li><a href=removeArticle.do?id=' + resources.artId + '>删除</a></li></ul></div></td></tr>'
                            );
                        });
                    });
                }
            });

        }
        /**
         * 技术运营
         */
        else if (curWwwPath.indexOf("one=Operating&two=Context") > 0) {
            /***
             * 进行AJAX请求
             */
            $.ajax({
                type: "POST",
                async: false,
                url: getRootPath() + "/manager/obtainArticle.do",
                data: "oneClass=Operating",
                success: function (data) {
                    //会话超时判断
                    if (data.length == 73) {
                        alert("会话已超时");
                        document.location = 'signin.html';
                    }

                    $.each(data.data, function (key, article) {
                        /**
                         * 遍历资源信息
                         */
                        $.each(article.resource, function (key, resources) {
                            $("#communalList").append(
                                '<tr><td>' + resources.id + '</td>' +
                                '<td>' + article.twoClass + '</td>' +
                                '<td>' + article.titleName + '</td>' +
                                '<td>' + resources.type + '</td>' +
                                '<td>' + resources.pathName + '</td>' +
                                '<td>' + resources.state + '</td>' +
                                '<td>' + resources.sorting + '</td>' +
                                '<td>' + resources.clickPath + '</td>' +
                                '<td><div class="btn-group"><a data-toggle="dropdown" class="dropdown-toggle"><i class="fa fa-cog"></i></a> <ul role="menu" class="dropdown-menu pull-right"><li><a href=updateContent.html?id=' + resources.id + '>修改</a></li><li><a href=removeArticle.do?id=' + resources.artId + '>删除</a></li></ul></div></td></tr>'
                            );
                        });


                    });
                }
            });
        }/**
         * 版权合作
         */
        else if (curWwwPath.indexOf("one=Copyright&two=Context") > 0) {
            /***
             * 进行AJAX请求
             */
            $.ajax({
                type: "POST",
                async: false,
                url: getRootPath() + "/manager/obtainArticle.do",
                data: "oneClass=Copyright",
                success: function (data) {
                    //会话超时判断
                    if (data.length == 73) {
                        alert("会话已超时");
                        document.location = 'signin.html';
                    }
                    $.each(data.data, function (key, article) {
                        /**
                         * 遍历资源信息
                         */
                        $.each(article.resource, function (key, resources) {
                            $("#communalContentId").attr("href", "addResource.html?artId=" + resources.artId);
                            $("#communalList").append(
                                '<tr><td>' + resources.id + '</td>' +
                                '<td>' + article.twoClass + '</td>' +
                                '<td>' + resources.name + '</td>' +
                                '<td>' + resources.type + '</td>' +
                                '<td>' + resources.pathName + '</td>' +
                                '<td>' + resources.state + '</td>' +
                                '<td>' + resources.sorting + '</td>' +
                                '<td>' + resources.clickPath + '</td>' +
                                '<td><div class="btn-group"><a data-toggle="dropdown" class="dropdown-toggle"><i class="fa fa-cog"></i></a> <ul role="menu" class="dropdown-menu pull-right"><li><a href=updateResource.html?id=' + resources.id + '>修改</a></li><li><a href=removeResource.do?resourceId=' + resources.id + '>删除</a></li></ul></div></td></tr>'
                            );
                        });
                    });
                }
            });

        }
        /**
         * 联系我们
         */
        else if (curWwwPath.indexOf("one=Contact&two=Context") > 0) {
            /***
             * 进行AJAX请求
             */
            $.ajax({
                type: "POST",
                async: false,
                url: getRootPath() + "/manager/obtainArticle.do",
                data: "oneClass=Contact",
                success: function (data) {
                    //会话超时判断
                    if (data.length == 73) {
                        alert("会话已超时");
                        document.location = 'signin.html';
                    }
                    $.each(data.data, function (key, article) {
                        /**
                         * 遍历资源信息
                         */
                        if (article.twoClass == 'TellQR') {
                            $.each(article.resource, function (key, resources) {
                                //向按钮添加文章Id
                                $("#tellQRButton").attr("href", "addResource.html?artId=" + resources.artId);
                                $("#contenetList").append(
                                    '<tr><td>' + resources.id + '</td>' +
                                    '<td>' + article.twoClass + '</td>' +
                                    '<td>' + resources.name + '</td>' +
                                    '<td>' + resources.type + '</td>' +
                                    '<td>' + resources.pathName + '</td>' +
                                    '<td>' + resources.state + '</td>' +
                                    '<td>' + resources.sorting + '</td>' +
                                    '<td>' + resources.clickPath + '</td>' +
                                    '<td><div class="btn-group"><a data-toggle="dropdown" class="dropdown-toggle"><i class="fa fa-cog"></i></a> <ul role="menu" class="dropdown-menu pull-right"><li><a href=updateResource.html?id=' + resources.id + '>修改</a></li><li><a href=removeResource.do?resourceId=' + resources.id + '>删除</a></li></ul></div></td></tr>'
                                );
                            });
                        }
                        //联系我们修改按钮大图
                        if (article.twoClass == 'Image') {
                            $("#tellPhoneTopBigImage").attr("href", " updateResource.html?id=" + article.resource[0].id);
                        } else {
                            $.each(article.resource, function (key, resources) {
                                $("#pageContextList").append(
                                    '<tr><td>' + resources.id + '</td>' +
                                    '<td>' + article.twoClass + '</td>' +
                                    '<td>' + article.titleName + '</td>' +
                                    '<td>' + resources.type + '</td>' +
                                    '<td>' + resources.pathName + '</td>' +
                                    '<td>' + resources.state + '</td>' +
                                    '<td>' + resources.sorting + '</td>' +
                                    '<td>' + resources.clickPath + '</td>' +
                                    '<td><div class="btn-group"><a data-toggle="dropdown" class="dropdown-toggle"><i class="fa fa-cog"></i></a> <ul role="menu" class="dropdown-menu pull-right"><li><a href=updateContent.html?id=' + resources.id + '>修改</a></li></ul></div></td></tr>'
                                );
                            });
                        }
                    });
                }
            });
        }

    });